package com.kd.mining.lda.core;

import java.io.IOException;

import com.kd.mining.lda.config.LDAConfig;


public class LdaGibbsSampler {
	
	public void start() {
		String originalDocsDir = LDAConfig.getOriginalDocDir();
		String resultDir = LDAConfig.getResultDocDir();
		String parameterFile= LDAConfig.getLDAParamFileName();
		
		try {
			// initialize LDA Model parameter
			ModelParameter ldaParameter = new ModelParameter();
			ldaParameter.init(parameterFile);
			// load document set
			Documents docSet = new Documents();
			docSet.load(originalDocsDir);
			// initialize LDA Model
			LDAModel model = new LDAModel(ldaParameter);
			model.init(docSet);
			System.out.println("start training...");
			// start train LDA model
			model.train(docSet, resultDir);
			System.out.println("finish to train.");
			System.out.println("estimate phi and theta distribution");
			// estimate
			model.estimate();
			System.out.println("save the last point");
			// save the last point
			model.savePoint(ldaParameter.getIteration(), docSet, resultDir);
			System.out.println("Success to Train by LDA!");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		new LdaGibbsSampler().start();
	}
}
